<template>
	<view class="page_bg">
		<!-- #ifdef APP-PLUS -->
		<view class="status_bar">
			<view class="top_view"></view>
		</view>
		<!-- #endif -->
		<view class="top_nav">
			<image src="/static/local/3546451940011a031009b939a8b26314.png" class="image_1" @click="pageBack" />
			<view class="cate">练习报告</view>
		</view>
		<scroll-view scroll-y="true" class="scroll_bg">
			<view class="flex-col section_2">
				<view class="flex-col items-center group_2">
					<custom-progress :value="rightPro" :border_width="16" class="cus_pro" :progress_time="600">
					</custom-progress>
					<view class="content">
						<text class="uni-text">答对</text>
						<text class="uni-text"><text class="hav">{{rightLength}}</text> /{{questionLength}}</text>
					</view>
				</view>
				<view class="flex-col group_4">
					<image src="/static/local/f763a2c78a597fab3f429dc5644387de.png" class="image_2" />
					<view class="flex-row group_5">
						<text class="text_4">{{type}}：</text>
						<text class="text_5">{{title}}</text>
					</view>
					<view class="flex-row group_6">
						<text class="text_6">交卷时间：</text>
						<text class="text_7">{{time}}</text>
					</view>
				</view>
			</view>
			<view class="answer_card">
				<view class="justify-between group_7">
					<text class="text_8">答题卡</text>
					<view class="flex-row group_8">
						<view class="flex-row">
							<image src="/static/local/0f815703ecb73750726312b7eed067da.png" class="image_3" />
							<text class="text_9">答对</text>
						</view>
						<view class="flex-row group_10">
							<image src="/static/local/8ccc46396aea17e452a88d24d521f0b3.png" class="image_3" />
							<text class="text_10">答错</text>
						</view>
						<view class="flex-row group_11">
							<image src="/static/local/db165dd417d5ea7ae30be04e28bcb3bc.png" class="image_3" />
							<text class="text_11">未答</text>
						</view>
					</view>
				</view>
				<view class="answer_show">
					<view class="group_12" v-if="single.length > 0">
						<view class="title">单选题</view>
						<view class="base_circle" :class="cType(item)" v-for="item in single">{{item.no}}</view>
					</view>

					<view class="group_12" v-if="more.length > 0">
						<view class="title">多选题</view>
						<view class="base_circle" :class="cType(item)" v-for="item in more">{{item.no}}</view>
					</view>

					<view class="group_12" v-if="judge.length > 0">
						<view class="title">判断题</view>
						<view class="base_circle" :class="cType(item)" v-for="item in judge">{{item.no}}</view>
					</view>
				</view>
			</view>
			<view class="empty"></view>
		</scroll-view>
		<view class="end_btns">
			<block v-if="questionLength > 0 && rightLength < questionLength">
				<view class="btn" @tap="jumpToCheck">全部解析</view>
				<view class="btn wrong" @tap="jumpToCheck">错误解析</view>
			</block>
			<block v-else>
				<view class="btn" @tap="back">返回题库</view>
			</block>
		</view>
	</view>
</template>

<script>
	var that; // 当前页面对象
	var vk; // vk依赖
	export default {
		data() {
			// 页面数据变量
			return {
				typeId: '',
				title: '',
				type: '',
				time: '',
				questionLength: 0,
				rightLength: 0,
				single: [],
				more: [],
				judge: []
			}
		},
		// 监听 - 页面每次【加载时】执行(如：前进)
		onLoad(options = {}) {
			that = this;
			vk = that.vk;
			that.init(options)
		},
		// 监听 - 页面【首次渲染完成时】执行。注意如果渲染速度快，会在页面进入动画完成前触发
		onReady() {},
		// 监听 - 页面每次【显示时】执行(如：前进和返回) (页面每次出现在屏幕上都触发，包括从下级页面点返回露出当前页面)
		onShow() {},
		// 监听 - 页面每次【隐藏时】执行(如：返回)
		onHide() {},
		// 函数
		computed: {
			// 准确率
			rightPro() {
				return this.rightLength / this.questionLength * 100
			},
			// 回答状态class
			cType() {
				return (item) => {
					switch (item.status) {
						case 1:
							return 'right'
						case 2:
							return 'wrong'
						default:
							return ''
					}
				}
			}
		},
		methods: {
			// 页面数据初始化函数
			init(options) {
				this.typeId = options.id
				this.title = options.title
				this.type = options.type
				this.time = options.time
				let data = vk.getStorageSync('exam-result')
				if (!data) return console.log('data is null!')
				this.questionLength = data.questions.length
				data.questions.map(v => {
					let obj = { no: v.no, status: null }
					let obj2 = data.answerCardNow[v._id]
					if (obj2) obj.status = obj2.a != null ? obj2.r : null
					if (obj.status == 1) this.rightLength++
					switch (v.type) {
						case '1':
							that.single.push(obj)
							break
						case '2':
							that.more.push(obj)
							break
						case '3':
							that.judge.push(obj)
							break
					}
				})
			},
			pageBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			// 跳转解析
			jumpToCheck() {
				uni.navigateTo({
					url: `/pages/question-bank/practice-page?pageTitle=${this.type}&id=${this.typeId}&check=true`
				});
			},
			back() {
				vk.navigateTo('/pages/question-bank/index');
				uni.$emit('bankUpdate');
			}
		},
	}
</script>

<style lang="scss" scoped>
	.page_bg {
		width: 100%;
		height: 100vh;
		background-image: url('../../static/local/16403089590017478445.png');
		background-position: 0px 0px;
		background-size: 100% 479rpx;
		background-repeat: no-repeat;

		.status_bar,
		.top_view {
			background-color: #FDCF03;
		}

		.top_nav {
			padding-bottom: 24rpx;
			color: rgb(51, 51, 51);
			font-size: 34rpx;
			line-height: 41rpx;
			white-space: nowrap;
			// height: 90rpx;
			position: relative;

			.image_1 {
				left: 21rpx;
				top: 27rpx;
				width: 19rpx;
				height: 35rpx;
				position: absolute;
			}

			.cate {
				width: 100%;
				padding: 20rpx 0;
				color: rgb(51, 51, 51);
				font-size: 34rpx;
				font-weight: 500;
				line-height: 41rpx;
				white-space: nowrap;
				text-align: center;
			}
		}

		.scroll_bg {
			height: calc(100% - 206rpx);
		}

		.section_2 {
			background-color: rgb(255, 255, 255);
			box-shadow: 0px 6rpx 16rpx 0px rgba(174, 99, 0, 0.12);
			border-radius: 12rpx;
			margin: 0 20rpx 16rpx;

			.group_2 {
				padding: 126rpx 0;
				position: relative;

				.cus_pro {
					transform: scale(0.7);
					position: absolute;
					top: 60rpx;
				}

				.content {
					font-size: 24rpx;
					position: absolute;
					top: 120rpx;
					display: flex;
					flex-direction: column;
					justify-content: center;
					color: #666666;

					.uni-text {
						text-align: center;
					}

					.hav {
						font-size: 52rpx;
						font-weight: bold;
						margin-right: 4rpx;
						line-height: 58rpx;
						color: #333;
					}
				}
			}

			.group_4 {
				padding-bottom: 34rpx;

				.image_2 {
					width: 94.5vw;
					height: 0.5vw;
				}

				.group_5 {
					margin-top: 24rpx;
					padding: 0 20rpx;

					.text_4 {
						color: rgb(153, 153, 153);
						font-size: 24rpx;
						line-height: 29rpx;
						white-space: nowrap;
					}

					.text_5 {
						margin-left: 15rpx;
						flex: 1 1 auto;
						color: rgb(51, 51, 51);
						font-size: 24rpx;
						line-height: 28rpx;
						text-align: left;
					}
				}

				.group_6 {
					margin-top: 35rpx;
					padding: 0 20rpx;

					.text_6 {
						color: rgb(153, 153, 153);
						font-size: 24rpx;
						line-height: 29rpx;
						white-space: nowrap;
					}

					.text_7 {
						margin-left: 15rpx;
						color: rgb(51, 51, 51);
						font-size: 24rpx;
						line-height: 29rpx;
						white-space: nowrap;
					}
				}
			}
		}

		.answer_card {
			background: #FFFFFF;
			box-shadow: 0px 6rpx 16rpx rgba(174, 99, 0, 0.12);
			border-radius: 12rpx;
			margin: 20rpx;
			padding: 34rpx 20rpx;

			.group_7 {
				padding-left: 16rpx;
				padding-right: 11rpx;
				align-items: center;

				.text_8 {
					color: rgb(51, 51, 51);
					font-size: 32rpx;
					line-height: 38rpx;
					white-space: nowrap;
				}

				.group_8 {
					color: rgb(51, 51, 51);
					font-size: 24rpx;
					white-space: nowrap;

					.flex-row {
						align-items: center;
					}

					.group_10 {
						margin-left: 39rpx;

						.text_10 {
							margin-left: 8rpx;
						}
					}

					.group_11 {
						margin-left: 39rpx;

						.text_11 {
							margin-left: 8rpx;
						}
					}

					.text_9 {
						margin-left: 8rpx;
					}

					.image_3 {
						margin: 5rpx 0;
						width: 18rpx;
						height: 18rpx;
					}
				}
			}

			.answer_show {
				.group_12 {
					display: flex;
					flex-wrap: wrap;

					.title {
						width: 100%;
						padding: 28rpx 0 12rpx 20rpx;
					}

					.base_circle {
						width: 72rpx;
						height: 72rpx;
						background: rgba(255, 255, 255, 0.39);
						border: 2rpx solid #999999;
						border-radius: 50%;
						text-align: center;
						line-height: 72rpx;
						margin: 0 4.4% 20rpx;
					}

					.wrong {
						color: #FFFFFF;
						background-color: #f90909;
						border-color: #f90909;
					}

					.right {
						color: #FFFFFF;
						background-color: #333;
						border-color: #333;
					}
				}
			}
		}

		.empty {
			height: 40rpx;
		}

		.end_btns {
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			padding: 26rpx 20rpx;
			background: #FFFFFF;
			font-size: 28rpx;
			box-shadow: 0px -6rpx 16rpx rgba(0, 0, 0, 0.08);
			display: flex;
			justify-content: space-around;

			.btn {
				width: 48%;
				height: 66rpx;
				background: #FFFFFF;
				border: 2rpx solid #333333;
				border-radius: 33rpx;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.wrong {
				background-color: #333333;
				color: #FFFFFF;
			}
		}
	}
</style>
